package com.example.wendao.model.db.dao;

import androidx.paging.DataSource;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.example.wendao.model.entity.Forum;


@Dao
public interface ForumDao {
    //生成新帖子
    @Insert
    void insertForum(Forum forum);

    // 查找所有的帖子
    @Query("SELECT * FROM Forum")
    DataSource.Factory<Integer, Forum> findByAllForum();

    // 查找最新提交的一个论坛帖
    @Query("select * from forum order by forumId desc limit 0, 1")
    Forum findLatestForum();

    //按照帖子id查找帖子
    @Query("select * from Forum where forumId = :forumid")
    Forum findForumById(int forumid);

    //按照用户id搜索其名下帖子
    @Query("SELECT * FROM Forum where forumAuthorId = :forumauthorid")
    DataSource.Factory<Integer, Forum> findAllForumByForumAuthorId(int forumauthorid);

    @Query("SELECT * FROM Forum where forumAuthorId = :forumauthorid")
    Forum[] findAllForumByForumAuthorIdInArray(int forumauthorid);

    //根据多个帖子id查找帖子
    /**
     * param:forumids
     * return: DataSource.Factory<Integer, Forum>
     */
    @Query("select * from Forum where forumId in (:forumids)")
    DataSource.Factory<Integer, Forum> findSomeForumsByForumIds(String forumids);

    //按照标签id搜索帖子
    @Query("SELECT * FROM Forum where forumTagId = :forumtagid")
    DataSource.Factory<Integer, Forum> findAllForumByForumTagId(int forumtagid);

    //按照标题模糊查找评论或回复
    @Query("SELECT * FROM Forum where forumTitle like :title")
    DataSource.Factory<Integer, Forum> findForumByTitle(String title);

    //更新评论或回复
    @Update
    void updateForum(Forum... forum);

    // 删除评论或回复
    @Delete
    void deleteForum(Forum... forums);

    @Query("select * from forum where forumTagId = :tagId")
    DataSource.Factory<Integer, Forum> findAllForumByTagId(int tagId);

}
